﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zor_DAL;
using Zor_Modes;
using Zor_Tools;
namespace Zor_Bll
{
    public class Zor_AnnualTask_Bll<T> where T : class
    {
        #region -年度计划任务管理 -
        /// <summary>
        /// 获取年度计划任务列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>
        public static List<T> GetPageList(dynamic annualtask, int index, out int TotalCount, string where)
        {
            where = "1=1";
            if (annualtask.At_StreetName != null)
                where += " and At_StreetName=" + annualtask.At_StreetName + "  ";
            if (annualtask.At_Year != "0" && annualtask.At_Year != null)
                where += " and At_Year=" + annualtask.At_Year + "  ";
            return PagerHelp<T>.GetPagerList(index, "V_Zor_AnnualTask", "At_Id", out TotalCount, where);
        }
        /// <summary>
        /// 查询所有街道
        /// create zhl by 2017.3.27     
        /// </summary>
        /// <returns></returns>
        public static List<T> SelectStreet()
        {
            return Zor_AnnualTask_DAL<T>.SelectStreet();      
        }

        /// <summary>
        /// 年度计划任务管理-新增
        /// create zhl by 17.3.27
        /// </summary>
        /// <param name="task">年度计划任务对象</param>
        /// <returns>执行结果：1 成功 0失败</returns>
        public static BaseAnswer InsertAnnualTask(Zor_AnnualTask task)
        {
            task.At_CreateDate = TimeHelper.ToTimeStamp(DateTime.Now);
            task.User_Id = RequestSession.GetSessionUser().User_Id;
            if (task.At_RevenuePlan != 0)
            {
                task.At_RevenuePlan = task.At_RevenuePlan * 10000 * 100;//转为分                
            }
            BaseAnswer bar = Zor_AnnualTask_DAL<T>.InsertAnnualTask(task);           
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "增加成功！" : "增加失败！";
            return bar;
        }

        /// <summary>
        /// 年度计划任务管理-修改
        /// create zhl by 17.3.27
        /// </summary>
        /// <param name="task">年度计划任务对象</param>
        /// <returns>执行结果：1 成功 0失败</returns>
        public static BaseAnswer UpdateAnnualTask(Zor_AnnualTask task)
        { 
            if (task.At_RevenuePlan != 0)
            {
                task.At_RevenuePlan = task.At_RevenuePlan * 10000 * 100;//转为分                
            }
            BaseAnswer bar = Zor_AnnualTask_DAL<T>.UpdateAnnualTask(task);           
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "修改成功！" : "修改失败！";
            return bar;
        }
        /// <summary>
        /// 删除年度计划任务
        /// create zhl by 17.3.27
        /// </summary>
        /// <param name="id">年度计划任务的id</param>
        /// <returns>1正常 返回0</returns>
        public static BaseAnswer DeleteAnnualTask(int[] id)
        {
            BaseAnswer bar = Zor_AnnualTask_DAL<T>.DeleteAnnualTask(id);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "删除成功！" : "删除失败！";
            return bar;
        }
        #endregion
    }
}
